<?php
/**
 * Digg pagination style
 *
 * @preview  « Previous  1 2 … 5 6 7 8 9 10 11 12 13 14 … 25 26  Next »
 */
    $page = Zend_Controller_Front::getInstance()->getRequest()->getParam('page');

    $this->total_items        = (int) max(0, $this->totalItemCount);
    $this->items_per_page     = (int) max(1, $this->itemCountPerPage);
    $this->total_pages        = (int) ceil($this->total_items / $this->items_per_page);
    $this->current_page       = (int) min(max(1, $page), max(1, $this->total_pages));
    $this->current_first_item = (int) min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items);
    $this->current_last_item  = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items);

    // If there is no first/last/previous/next page, relative to the
    // current page, value is set to FALSE. Valid page number otherwise.
    $this->first_page         = ($this->current_page == 1) ? FALSE : 1;
    $this->last_page          = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages;
    $this->previous_page      = ($this->current_page > 1) ? $this->current_page - 1 : FALSE;
    $this->next_page          = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE;

    $request = Zend_Controller_Front::getInstance()->getRequest();
    $path_info = $request->getRequestUri();
    if('/' == $path_info) {
        $path_info = $this->url(array(), 'index_chain');
    }

    if(preg_match('/page/i', $path_info)) {
        $url = preg_replace('/page\/?[^\/]*/i', 'page/:page', $path_info);
    } else {
        $url = $path_info . '/page/:page/';
    }

    //$url = preg_replace('/\/{2,}/', '/', $url); //заменяем больше 2х слешов подряк на 1 слеш.
?>


<div class="bar corner-all paginator">
     <ul class="paginator-content paginator-background-spr line-background">
     <li>
	<?php if ($this->previous_page): ?>
		<a class="paginator-background-spr previous-page" href="<?= str_replace(':page', $this->previous_page, $url) ?>"></a>
	<?php else: ?>

		<a class="paginator-background-spr previous-page" href="../" onclick="return false;"></a>
	<?php endif ?>
	</li>

	<?php if ($this->total_pages < 11): /* « Previous  1 2 3 4 5 6 7 8 9 10 11 12  Next » */ ?>

		<?php for ($i = 1; $i <= $this->total_pages; $i++): ?>
			<?php if ($i == $this->current_page): ?>
				<li class="active"><a class="paginator-background-spr s-active-bg" href="../" onclick="return false;"><?php echo $i ?></a> <span></span></li>
			<?php else: ?>
				<li><a href="<?= str_replace(':page', $i, $url); ?>"><?php echo $i ?></a><span></span></li>
			<?php endif ?>
		<?php endfor ?>

	<?php elseif ($this->current_page < 7): /* « Previous  1 2 3 4 5 6 7 8 9 10 … 25 26  Next » */ ?>

		<?php for ($i = 1; $i <= 8; $i++): ?>
			<?php if ($i == $this->current_page): ?>
				<li class="active"><a class="paginator-background-spr s-active-bg" href="../" onclick="return false;"><?php echo $i ?></a> <span></span></li>
			<?php else: ?>
				<li><a href="<?= str_replace(':page',$i, $url) ?>"><?php echo $i ?></a><span></span></li>
			<?php endif ?>
		<?php endfor ?>

		<li class="paginator-background-spr dotted"></li>
		<li><a href="<?= str_replace(':page', $this->total_pages - 1, $url); ?>"><?php echo $this->total_pages - 1 ?></a><span></span></li>
		<li><a href="<?= str_replace(':page', $this->total_pages, $url) ?>"><?php echo $this->total_pages ?></a><span></span></li>

	<?php elseif ($this->current_page > $this->total_pages - 6): /* « Previous  1 2 … 17 18 19 20 21 22 23 24 25 26  Next » */ ?>

        <li><a href="<?= str_replace(':page', "1", $url); ?>">1</a><span></span></li>
		<li><a href="<?= str_replace(':page', "2", $url); ?>">2</a><span></span></li>
		<li class="paginator-background-spr dotted"></li>

		<?php for ($i = $this->total_pages - 7; $i <= $this->total_pages; $i++): ?>
			<?php if ($i == $this->current_page): ?>
				<li class="active"><a class="paginator-background-spr s-active-bg" href="../" onclick="return false;"><?php echo $i ?></a> <span></span></li>
			<?php else: ?>
			<li><a href="<?= str_replace(':page',$i, $url); ?>"><?php echo $i ?></a><span></span></li>
			<?php endif ?>
		<?php endfor ?>

	<?php else: /* « Previous  1 2 … 5 6 7 8 9 10 11 12 13 14 … 25 26  Next » */ ?>

		<li><a href="<?=$url.'1'; ?>">1</a><span></span></li>
		<li><a href="<?=$url.'2'; ?>">2</a><span></span></li>
		<li class="paginator-background-spr dotted"></li>

		<?php for ($i = $this->current_page - 4; $i <= $this->current_page + 4; $i++): ?>
			<?php if ($i == $this->current_page): ?>
				<li class="active"><a class="paginator-background-spr s-active-bg" href="../" onclick="return false;"><?php echo $i ?></a> <span></span></li>
			<?php else: ?>
				<li><a href="<?= str_replace(':page', $i, $url) ?>"><?php echo $i ?></a><span></span></li>
			<?php endif ?>
		<?php endfor ?>

		<li class="paginator-background-spr dotted"></li>
		<li><a href="<?= str_replace(':page', $this->total_pages - 1, $url) ?>"><?php echo ($this->total_pages - 1); ?></a><span></span></li>
		<li><a href="<?= str_replace(':page', $this->total_pages, $url) ?>"><?php echo $this->total_pages ?></a><span></span></li>

	<?php endif ?>

	<li class="last">
	<?php if ($this->next_page): ?>
		<a class="paginator-background-spr next-page" href="<?= str_replace(':page', $this->next_page, $url) ?>"></a>
	<?php else: ?>
		<a class="paginator-background-spr next-page" onclick="return false;" href="<?= str_replace(':page', $this->next_page, $url) ?>"></a>
	<?php endif ?>
	</li>

	</ul>
</div>